<template>
<!--    布局-->
    <el-container class="home">
<!--        头部-->
        <el-header>
            <div>
                <img class="img1" src="../../assets/images/动图.gif" alt="">
                <span>电商后台管理系统</span>
                <img class="img2" src="../../assets/images/780.jpg" alt="">
            </div>
            <!--退出-->
            <el-button type="danger" @click="over">退出登录</el-button>
        </el-header>
        <el-container>
<!--            左侧-->
            <el-aside :width="collapseShut ? 64+'px' : 200+'px' ">
                <!--导航栏-->
<!--                折叠-->
                <div class="shut" @click="changeCollapse">
                    <span>|</span>
                    <span>|</span>
                    <span>|</span>
                </div>
                <el-menu
                        background-color="#363e50"
                        text-color="#fff"
                        active-text-color="#409EFF"
                        unique-opened
                        :collapse="collapseShut"
                        :collapse-transition="false"
                        :router="true"
                        :default-active="activePath">
                    <!--第一层导航栏-->
                    <el-submenu :index="item.id+''" v-for="item in menuList" :key="item.id">
                        <template slot="title">
                            <i :class="iconFonts[item.id]"></i>
                            <span>{{item.authName}}</span>
                        </template>
<!--                        第二层导航栏-->
                        <el-menu-item
                                :index="'/'+minItem.path"
                                v-for="minItem in item.children"
                                :key="minItem.id"
                                @click="activeItem('/'+minItem.path)">
                            <i class="el-icon-menu"></i>
                            <span>{{minItem.authName}}</span>
                        </el-menu-item>
                    </el-submenu>
                </el-menu>
            </el-aside>
<!--            中间内容区-->
            <el-main>
                <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>
</template>

<script>
    export default {
        name: "home",
        data(){
            return{
                // 菜单列表数据
                menuList:[],
                // 列表项字体库数据
                iconFonts:{
                    '125':'iconfont icon-icon-test4',
                    '103':'iconfont icon-icon-test3',
                    '101':'iconfont icon-icon-test2',
                    '102':'iconfont icon-icon-test1',
                    '145':'iconfont icon-icon-test'
                },
                // 是否折叠列表
                collapseShut:false,
                // 点击的path值
                activePath:''
            }
        },
        created(){
          this.getMenu()
            this.activePath = window.sessionStorage.getItem('activePath')
        },
        methods:{
            over(){
                window.sessionStorage.clear()
                this.$router.push('/login')
            },
            getMenu(){
                this.$http.get('menus').then((res) => {
                    if (res.data.meta.status !== 200) return this.$message.error(res.data.meta.msg)
                    this.menuList = res.data.data
                })
            },
            changeCollapse(){
                this.collapseShut = !this.collapseShut
            },
            activeItem(path){
                window.sessionStorage.setItem('activePath',path)
                this.activePath = path
            }
        }
    }
</script>

<style scoped lang="less">
    .home{
        height: 100%;
    }
    .el-header{
        background-color: #33393c;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-left: 0;
        div{
            display: flex;
            align-items: center;
            .img1{
                width: 70px;
                box-shadow: 0 0 10px #fff;
                border-radius: 50%;
            }
            .img2{
                width: 150px;
                box-shadow: 0 0 10px #fff;
                border-radius: 50%;
                margin-left: 400px;
            }
            span{
                font-size: 22px;
                color: #fff;
                margin-left: 20px;
            }
        }
    }
    .el-aside{
        background-color: #363e50;
    }
    .el-main{
        background-color: #e7ecef;
    }
    .iconfont{
        margin-right: 8px;
    }
    .el-menu{
        border: none;
    }
    .shut{
        background-color: #4b5567;
        width: 100%;
        height: 35px;
        line-height: 35px;
        font-size: 20px;
        color: #fff;
        text-align: center;
        cursor: pointer;
        span{
            margin-left: 2px;
        }
    }


</style>